﻿/*20120518 新增交接班信息框，提供白夜班交接信息记录*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PPT.Common;
using System.IO;
using System.Net;
using System.Net.Sockets;
using Utile;
using MESLibs.PPT;
using WMS.Common;

namespace TMFC
{
    public partial class frmMainMenu : Form
    {
        float[] WW, HH;
        float[] XX, YY;
        int conqty = 0;
        int frmleft;
        int p_row = 0;//记录grdNgr表格行数
        USM.USMFunc USMFunc = new USM.USMFunc();

        private Form frmNow;
        DB.DB DBLink = new DB.DB();
        private List<ComboBoxItem> _Processes = new List<ComboBoxItem>();
        private ProduceInfoReport _ObjPIR;
        string strcurprcs = "";
        Boolean okflag = false;
        public frmMainMenu(string UserNow)
        {
            Global.gUserID = UserNow;
            InitializeComponent();
            conqty = this.Controls.Count;

        }

        private void frmMainMenu_Load(object sender, EventArgs e)
        {
            //skinEngine1.SkinFile = Application.StartupPath + @"\MacOS.ssk";  //换皮肤
            WW = new float[conqty]; HH = new float[conqty];
            XX = new float[conqty]; YY = new float[conqty];
            //强制显示公告栏10s
            //this.timer1.Start();
            // menuStrip1.Enabled = false;
            //Information();
            //同步Client端PC和DB server之时间by George
            //baggio string chkTime = CSyncTime.CSyncTimeClass.SyncTimeFunc(1, DBLink.dbConn, 200);
            string chkTime = "OK";
            if (chkTime != "OK")
            {
                MessageBox.Show("同步DB时间时发生异常!");
                //    return;a
            }
            //主画面上显示程序版本by George 990820

            //20100422 主画面上显示登入人员工号 by Jack Yang
            this.Text = this.Text + " :: 登入人员 [" + Global.gUserID.ToString() + "] ::";
            //主画面上显示程序版本by George 990820
            string startpath = Application.StartupPath;
            StreamReader verStr = new StreamReader(@startpath + "\\Config.ini");
            this.Text = this.Text + " @版本:" + verStr.ReadLine();
            verStr.Close();
            verStr.Dispose();
            verStr = null;
            // 将所有程序选单 Load 到 Menu 上

            //修正Config.ini年份
            try
            {
                chkCorrectYear();
            }
            catch { }

            // 将所有选项 disable
            foreach (ToolStripMenuItem mi in this.menuStrip1.Items)
            {
                // string a = mi.Name;
                foreach (ToolStripDropDownItem ddi in mi.DropDownItems)
                {
                    // string b = ddi.Name;

                    if (mi.Name.ToString().Equals("MenuUSM"))
                        ddi.Visible = false;
                    else
                        ddi.Enabled = false;
                }
            }

            // 依照登入人员的群组决定可以使用的功能选项
            DataTable dtTable = new DataTable();
            string strResult = USM.USMFunc.getMainMenuList(Global.gUserID, dtTable);
            if (!strResult.Equals("") || dtTable.Rows.Count == 0)
            {
                MessageBox.Show(this, "登录权限查询错误，请与 CIM 工程师联络!", "权限错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

                //20100423 登入权限如果错误就不要进到MES主程序画面 by Jack Yang
                GC.Collect();
                this.Close();

            }
            else
            {
                for (int i = 0; i < dtTable.Rows.Count; i++)
                {
                    foreach (ToolStripMenuItem mi in this.menuStrip1.Items)
                    {
                        foreach (ToolStripDropDownItem ddi in mi.DropDownItems)
                        {
                            if (ddi.Name.Equals(dtTable.Rows[i]["id_func"].ToString()))
                            {
                                if (mi.Name.ToString().Equals("MenuUSM"))
                                    ddi.Visible = true;
                                else
                                    ddi.Enabled = true;

                            }
                        }
                    }
                    ////是否显示交接班
                    //     iniinfomationintofrom();
                }

            }
            Global.SetPPTPara();
            //显示交接班
            foreach (Control btn in this.Controls)
            {
                if (btn.GetType().FullName == "System.Windows.Forms.Button")
                {
                    if (btn.Name != "btnExit")
                        ((Button)btn).Enabled = false;
                }
            }

            if (_Processes.Count == 0)  //一开始没有预设站别编号
            {
                _ObjPIR = new ProduceInfoReport(PPT.Global.GetDBConnObject());
                string[] aryPrcs = _ObjPIR.GetProcessList(ProduceInfoReport.ProcessDataType.Release);
                foreach (string prcs in aryPrcs)
                    _Processes.Add(new ComboBoxItem(prcs, prcs));
                //设定数据成员

                //cboPrcsID.DataSource = _Processes;
                //cboPrcsID.DisplayMember = "Text";
                //cboPrcsID.ValueMember = "Value";
            }
            // 呼叫 USM.getIDAuthority 显示画面上权限(By Button)
            strResult = clsUtile.DisplayForm(Global.gUserID, "MAN001", this);


            ////strcurprcs
            string strIP = "10.12.13.36";
            /*baggio
            string strHostName = Dns.GetHostName();

            IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
            
            foreach (IPAddress ip in iphostentry.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    if (ip.ToString().Substring(0, 3) == "192" || ip.ToString().Substring(0, 3) == "10.")
                    {
                        strIP = ip.ToString();
                        break;
                    }
                }
            }
            baggio*/
            DataTable dtTable2 = new DataTable();

            string strSQL = "select ip.*,fd.dsc_cod1 from fdprcsip ip,fdsyscod_d fd where id_ip = '" + strIP + "'" +
                " and fd.id_cod='IDFAB' and fd.lin_cod=ip.id_fab";
            string stResult = DBLink.executeQuery(strSQL, dtTable2);
            if (!stResult.Equals(""))
            {
                MessageBox.Show("取得本电脑的归属厂别、线别及站别资讯时发生异常!! 请与 CIM 人员联络!!");

                dtTable2.Dispose();
                dtTable2 = null;

                GC.Collect();
                this.Close();

            }
            else
            {
                strcurprcs = dtTable2.Rows[0]["id_prcs"].ToString();
            }

            //iniinfomationintofrom();
            okflag = true;
            /**************************************20120905 shiping****************************/
            frmleft = this.Width;
            //button1.Visible = false;
            // btn_dft_right.Enabled = true; btn_dft_left.Enabled = true;
            for (int i = 0; i <= conqty - 1; i++)
            {

                if (!Controls[i].Name.Equals("txtbxleft") || !Controls[i].Name.Equals("txtbxright") || !Controls[i].Name.Equals("btn_dft_leftDetails") || !Controls[i].Name.Equals("btn_dft_rightDetails"))
                {
                    WW[i] = this.Width / Controls[i].Width;
                    HH[i] = this.Height / Controls[i].Height;
                    XX[i] = Controls[i].Location.X;
                    YY[i] = Controls[i].Location.Y;
                }
                else
                {
                    WW[i] = this.Width / Controls[i].Width;
                    HH[i] = this.Height / Controls[i].Height;
                }
            }
            //  pictureBox1.Image = Image.FromFile("tainergy.jpg");
            //Application.StartupPath + @"\TMFC\"
            //  if (Directory.Exists(Application.StartupPath + @"\tainergy.jpg") == true)
            {
                //     pictureBox1.Image = Image.FromFile(Application.StartupPath + @"\tainergy.jpg");



            }
            //   else if  (Directory.Exists(Application.StartupPath + @"\TMFC.exe")==true )
            {
            }
            //if (strcurprcs.Equals("ADMIN"))
            //{
            //    label1.Visible = false;
            //   // menuStrip1.Enabled = true ;
            ////    timer1.Stop();
            //}

            /*******************************20120905 shiping********************************/
            // System.Threading.Thread.Sleep(10000);

            loadDeptOnNgr();


            //add by wzf 2015.09.07 IVQ模组下只有IVQ002 && IVQ003 可用，其它都暂时设为不可用
            IVQ001.Enabled = false;
            IVQ004.Enabled = false;
            IVQP001.Enabled = false;
            IVQP002.Enabled = false;
            IVQP003.Enabled = false;
            IVQR002.Enabled = false;
            IVQI001.Enabled = false;
            IVQI002.Enabled = false;
            IVQI003.Enabled = false;
            IVQQ001.Enabled = false;
            IVQMail.Enabled = false;

            PPT004.Visible = false;
            PPT007.Visible = false;
            PPT008.Visible = false;
            PPT009.Visible = false;
            PPT025.Visible = false;

            //MMS007.Enabled = false;
            //PPT076.Visible = false;
            // For 异常联络单 By Baggio
            btnNewNgr.Enabled = true;
            btnViewNgr.Enabled = true;
            btnSelectNgr.Enabled = true;
            btnSelectAllNgr.Enabled = true;
            button1.Enabled = true;

            //操作ngr单入口
            runNgrModule();
        }

        private void ShowForm()
        {
            ////string startpath = Application.StartupPath;
            ////StreamReader verStr = new StreamReader(@startpath + "\\Config.ini");
            ////string startpath = "\\192.168.1.3\\share\\Release\\TMFC_NEW\\Config.ini";
            //string startpath = @"Z:/Release/TMFC_NEW/Config.ini";
            //StreamReader verStr = new StreamReader(startpath);
            //string sysupdatedatetime = verStr.ReadLine();
            //string nowupdatedatetime = this.Text.Substring(this.Text.Length - 19, 19);
            //if (!DateTime.Parse(sysupdatedatetime).ToString("yyyy-MM-dd").Equals(DateTime.Parse(nowupdatedatetime).ToString("yyyy-MM-dd")))
            //{
            //    MessageBox.Show("系统已更新,请关闭MES再重新打开!");
            //    return;
            //}
            /*baggio
            string strResult = PPT.Global.checkNewVersion();
            //暂改by George 20110622
            //    string strResult = "";
            if (strResult != "")
            {
                MessageBox.Show(strResult);
                GC.Collect();
                this.Close();
                return;
            }
            baggio*/
            if (frmNow == null)
                return;
            //grdNgr.DefaultCellStyle.BackColor = Color.Transparent;
            frmNow.ShowDialog();
        }

        #region BRM Function
        private void BRM001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            //frmNow = new BRM.frmBRM001();
            frmNow = new BRM.frmBRM001(Global.gUserID);

            ShowForm();

        }

        private void BRM003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM003();
            frmNow = new BRM.frmBRM003(Global.gUserID);

            ShowForm();

        }

        private void BRM005_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM005();
            frmNow = new BRM.frmBRM005(Global.gUserID);

            ShowForm();
        }

        private void BRM007_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM007();
            frmNow = new BRM.frmBRM007(Global.gUserID);

            ShowForm();
        }

        private void BRM009_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM009();
            frmNow = new BRM.frmBRM009(Global.gUserID);

            ShowForm();
        }

        private void BRM011_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM011();
            frmNow = new BRM.frmBRM011(Global.gUserID);

            ShowForm();
        }

        private void BRM013_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM013();
            frmNow = new BRM.frmBRM013(Global.gUserID);

            ShowForm();
        }

        #endregion

        #region SCH Function
        private void SCH001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new SCH.frmSCH001();
            frmNow = new SCH.frmSCH001(Global.gUserID);

            ShowForm();
        }

        private void SCH003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new SCH.frmSCH003();
            frmNow = new SCH.frmSCH003(Global.gUserID);

            ShowForm();
        }

        #endregion

        #region PPT Function

        // PPT001 工单投产作业
        private void PPT001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090821 Jeffery Modify
            // frmNow = new PPT.frmPPT001();
            frmNow = new PPT.frmPPT001(Global.gUserID);
            Global.SetPPTPara();
            ShowForm();

        }

        // PPT004 生产信息回报
        private void PPT004_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090821 Jeffery Modify
            // frmNow = new PPT.frmPPT004();
            frmNow = new PPT.frmPPT004(Global.gUserID);
            Global.SetPPTPara();
            ShowForm();
        }

        // PPT010 Repair 回报作业
        private void PPT010_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090821 Jeffery Modify
            // frmNow = new PPT.frmPPT010();
            frmNow = new PPT.frmPPT044(Global.gUserID);
            Global.SetPPTPara();
            ShowForm();
        }

        #endregion

        #region USM Function
        private void USM001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new USM.frmUSM001(Global.gUserID);
            ShowForm();
        }

        private void USM002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new USM.frmUSM002(Global.gUserID);
            ShowForm();
        }

        private void USM003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new USM.frmUSM003(Global.gUserID);
            ShowForm();
        }

        private void USM006_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new USM.frmUSM006(Global.gUserID);
            ShowForm();
        }

        #endregion


        private void SCH009_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new SCH.frmSCH009(Global.gUserID, "", "");
            ShowForm();
        }

        private void PPT011_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT011(Global.gUserID);

            ShowForm();
        }

        private void PPT012_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            //  Form frmQry = new frmPPT050(strIDUser);
            // frmQry.ShowDialog();
            //frmNow = new PPT.frmPPT012(Global.gUserID);
            frmNow = new PPT.frmPPT050(Global.gUserID);


            ShowForm();
        }

        private void PPT013_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT013("Exec", "", Global.gUserID, Global.gFabID, Global.gLineID, Global.gPrcsID);

            ShowForm();
        }

        private void PPT015_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT015(Global.gUserID);

            ShowForm();
        }

        private void PPT016_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT016(Global.gUserID);

            ShowForm();
        }
        /*
        private void BRM020_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            // 20090818 Jeffery Modify
            // frmNow = new BRM.frmBRM013();
            frmNow = new BRM.frmBRM020(Global.gUserID);

            ShowForm();
        }
        */
        private void PPT009_Click(object sender, EventArgs e)
        {
            //if (frmNow != null)
            //    progressCtrl();
            //frmNow = new PPT.frmPPT009(Global.gUserID);

            //ShowForm();
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new PPT.frmPPT066(Global.gUserID);

            ShowForm();
        }

        private void PPT018_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT018(Global.gUserID);

            ShowForm();
        }

        private void PPT020_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT020(Global.gUserID, true);

            ShowForm();
        }

        private void PPT022_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT022(Global.gUserID, false);

            ShowForm();
        }


        private void PPT023_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT023(Global.gUserID, true);

            ShowForm();
        }

        private void PPT024_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT024(Global.gUserID, false, "", "", "");

            ShowForm();
        }

        private void PPT025_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT025("", "", Global.gUserID, false);

            ShowForm();
        }

        private void PPT026_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT026(Global.gUserID);

            ShowForm();
        }

        private void PPT033_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT033(Global.gUserID);

            ShowForm();
        }

        private void PPT034_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT034(Global.gUserID);

            ShowForm();
        }

        private void PPT036_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT036(Global.gUserID);

            ShowForm();
        }


        private void PPT008_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT008(Global.gUserID, Global.gPrcsID);

            ShowForm();
        }

        private void PPT038_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT038(Global.gUserID);

            ShowForm();
        }

        private void PPT039_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT039(Global.gUserID);

            ShowForm();
        }

        private void MenuRPT_Click(object sender, EventArgs e)
        {

        }

        private void RPT001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT001(Global.gUserID);

            ShowForm();
        }

        private void RPT002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT009(Global.gUserID, Global.gFabID);
            // frmNow.ShowDialog();
            ShowForm();
        }

        //因为测试需要，暂时关闭版本更新 2012/03/12 By Baggio.yan

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

            //增加每次点选MenuItem时检查MES系统版本by George 991207
            if (e.ClickedItem.Name == "MenuExit")
                return;
            //取得本机IP
            // 取得登入系统 的 PC 的 IP => 判断该批西所归属的厂别、线别及站别!!
            string strIP = "";

            // 01.取得本机名称
            string strHostName = Dns.GetHostName();

            // 02.取得本机的 IpHostEntry 类别实体
            IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
            //    IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
            // 03.取得 IP 地址
            // 因应Win7用原方式会有问题,改以下方式get IP by George 991013
            foreach (IPAddress ip in iphostentry.AddressList)
            {

                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    if (ip.ToString().Substring(0, 3) == "192" || ip.ToString().Substring(0, 3) == "10.")
                    {
                        strIP = ip.ToString();
                        break;
                    }
                }
            }
            //↑↑
            string ServerIP = "";
            StreamReader strReader;
            if (strIP.Substring(0, 3) == "192")
            {
                ServerIP = "192.168.1.3";
                strReader = new StreamReader(@"\\" + ServerIP + @"\share\Release\TMFC\" + "Config.ini");
            }
            else if (strIP.Substring(0, 3) == "10.")
            {
                ServerIP = "10.12.1.3";
                strReader = new StreamReader(@"\\" + ServerIP + @"\v\03-PUBLIC\506.制造系统整合部_CIM\昆山专用 勿动\Release\TMFC\" + "Config.ini");
            }
            else
            {
                strReader = new StreamReader(@"\\" + ServerIP + @"\Release\TMFC\" + "Config.ini");
            }
            DateTime dtServer = new DateTime();
            DateTime dtLocal = new DateTime();
            // 01.取得 Server 端 ini 设定的 ReleaseDate   \\10.11.5.15\share\Release\TMFC\

            while (strReader.Peek() > -1)
            {
                dtServer = DateTime.Parse(strReader.ReadLine());
            }
            strReader.Close();

            // 02.取得本机端 Config 设定 ReleaseDate
            string Localpath = "";
            if (Directory.Exists(Application.StartupPath + @"\TMFC\") == true)
                Localpath = Application.StartupPath + @"\TMFC\" + "Config.ini";
            else
                Localpath = Application.StartupPath + @"\" + "Config.ini";
            strReader = new StreamReader(@Localpath);
            while (strReader.Peek() > -1)
            {
                dtLocal = DateTime.Parse(strReader.ReadLine());
            }
            strReader.Close();

            if (dtLocal < dtServer)
            {
                MessageBox.Show("Server主机上有较新版本!程序关闭后请重启MES系统以更新程序!");
                GC.Collect();
                this.Close();
            }

        }

        private void PPT040_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT040(Global.gUserID);

            ShowForm();
        }

        private void PPT041_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT041(Global.gUserID);

            ShowForm();
        }

        private void RPT005_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT005(Global.gUserID);

            ShowForm();
        }

        private void RPT006_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT006(Global.gUserID);

            ShowForm();
        }

        private void PPT007_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT007(Global.gUserID, Global.gPrcsID);

            ShowForm();
        }

        private void RPT007_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT007(Global.gUserID, Global.gFabID);

            ShowForm();
        }

        private void MMS001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new MMS.frmMMS001(Global.gUserID, Global.gFabID);

            ShowForm();
        }

        private void RPT010_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT010(Global.gUserID);

            ShowForm();
        }

        private void RPT012_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT012(Global.gUserID);

            ShowForm();
        }

        private void PPT046_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT046(Global.gUserID);

            ShowForm();
        }

        private void chkCorrectYear()
        {
            //把Config.ini异动回正常时间
            string starpath = Application.StartupPath.ToString();
            if (starpath.IndexOf("MESUpdate") > 0)
                starpath = starpath.Replace("MESUpdate", "MES");
            StreamReader strRead = new StreamReader(starpath + @"\Config.ini");
            string updDate = strRead.ReadLine();
            strRead.Close();
            strRead.Dispose();
            strRead = null;

            if (updDate.IndexOf("2011") >= 0)
                updDate = updDate.Replace("2011", "2012");
            StreamWriter strWrite = new StreamWriter(starpath + @"\Config.ini");
            strWrite.Write(updDate);

            strWrite.Dispose();
            strWrite = null;
        }

        private void RPT013_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT013(Global.gUserID);

            ShowForm();
        }

        private void PPT049_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT049(Global.gUserID);

            ShowForm();
        }

        private void RPT014_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new RPT.frmRPT014(Global.gUserID);

            ShowForm();
        }

        private void PPT051_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new PPT051.frmPPT051(Global.gUserID);

            ShowForm();
        }

        private void PPT062_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new PPT.frmPPT062(Global.gUserID);

            ShowForm();
        }

        private void pPT051IV标示牌建立打印系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //  if (frmNow != null)
            //     progressCtrl();
            //  frmNow = new PPT051_T.frmPPT051(Global.gUserID);

            // ShowForm();
        }

        private void pPT051IV标示牌建立打印系统实验用ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // if (frmNow != null)
            //     progressCtrl();
            //  frmNow = new PPT051_T.frmPPT051(Global.gUserID);

            // ShowForm();
        }

        private void RPT015_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new RPT015.frmRPT015();
            ShowForm();

        }

        private void RPT016_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new EQUtilization.fmEQUtilization();
            ShowForm();
        }

        private void RPT017_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new EQUtilization.EQU001();
            ShowForm();
        }

        private void RPT018_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new EQUtilization.EQU002();
            ShowForm();
        }

        //private void iniinfomationintofrom()
        //{
        //    string strResult = "";
        //    string strSQL = "";
        //    var tmpTable = new DataTable();
        //    //0001白班交接班信息
        //    strSQL = "select * from (select * from FRSHIFT_L where shift_prod='日班'   and type='W' ";
        //    if (!strcurprcs.Equals("ADMIN"))
        //    {
        //        strSQL = strSQL + " and id_prcs='" + cboPrcsID.Text.Trim() + "' ";
        //    }


        //    // strSQL = strSQL + "order by dat_trn desc ,tim_trn desc) where dat_trn >= to_char(sysdate -1, 'yyyy/mm/dd')";
        //    strSQL = strSQL + "order by dat_trn desc ,tim_trn desc) where rownum<=1";

        //    strResult = DBLink.executeQuery(strSQL, tmpTable);

        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("查询白班交接班信息时发生异常!");
        //    }
        //    if (tmpTable.Rows.Count > 0)
        //    {/*
        //        for (int i = 0; i <= tmpTable.Rows.Count - 1; i++)
        //        {
        //            txtbxleft.Text += tmpTable.Rows[i]["note"].ToString();
        //        }*/
        //        //
        //        txtbxleft.Text = tmpTable.Rows[0]["note"].ToString();
        //        Lblleft.Text = tmpTable.Rows[0]["usr_trn"].ToString() + ": " + tmpTable.Rows[0]["dat_trn"].ToString() + "/" + tmpTable.Rows[0]["tim_trn"].ToString();
        //    }
        //    else
        //    {
        //        txtbxleft.Text = "无信息";
        //    }
        //    //0002夜班交接班信息
        //    var tmpTable1 = new DataTable();
        //    strSQL = "select * from (select * from FRSHIFT_L where shift_prod='夜班'    and type='W'  ";
        //    if (!strcurprcs.Equals("ADMIN"))
        //    {
        //        strSQL = strSQL + " and id_prcs='" + cboPrcsID.Text.Trim() + "' ";
        //    }

        //    strSQL = strSQL + "order by dat_trn desc ,tim_trn desc) where rownum<=1";
        //    strResult = DBLink.executeQuery(strSQL, tmpTable1);
        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("查询夜班交接班信息时发生异常!");
        //    }

        //    if (tmpTable1.Rows.Count > 0)
        //    {
        //        txtbxright.Text = tmpTable1.Rows[0]["note"].ToString();
        //        Lblright.Text = tmpTable1.Rows[0]["usr_trn"].ToString() + ": " + tmpTable1.Rows[0]["dat_trn"].ToString() + "/" + tmpTable1.Rows[0]["tim_trn"].ToString();
        //    }
        //    else
        //    {
        //        txtbxright.Text = "无信息";
        //    }
        //    //0003白班异常回报
        //    var tmpTable2 = new DataTable();
        //    strSQL = "select * from (select * from FRSHIFT_L where shift_prod='日班'   and type='M' ";
        //    if (!strcurprcs.Equals("ADMIN"))
        //    {
        //        strSQL = strSQL + " and id_prcs='" + cboPrcsID.Text.Trim() + "' ";
        //    }

        //    strSQL = strSQL + "order by dat_trn desc ,tim_trn desc) where rownum<=1";

        //    strResult = DBLink.executeQuery(strSQL, tmpTable2);

        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("查询白班交接班信息时发生异常!");
        //    }
        //    if (tmpTable2.Rows.Count > 0)
        //    {
        //        btn_dft_leftDetails.Text = tmpTable2.Rows[0]["note"].ToString();
        //        btn_dft_leftinfo.Text = tmpTable2.Rows[0]["usr_trn"].ToString() + ": " + tmpTable2.Rows[0]["dat_trn"].ToString() + "/" + tmpTable2.Rows[0]["tim_trn"].ToString();
        //    }
        //    else
        //    {
        //        btn_dft_leftDetails.Text = "无信息";
        //    }
        //    //0004夜班异常回报
        //    var tmpTable3 = new DataTable();
        //    strSQL = "select * from (select * from FRSHIFT_L where shift_prod='夜班'    and type='M'  ";
        //    if (!strcurprcs.Equals("ADMIN"))
        //    {
        //        strSQL = strSQL + " and id_prcs='" + cboPrcsID.Text.Trim() + "' ";
        //    }

        //    strSQL = strSQL + "order by dat_trn desc ,tim_trn desc) where rownum<=1";
        //    strResult = DBLink.executeQuery(strSQL, tmpTable3);
        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("查询夜班交接班信息时发生异常!");
        //    }

        //    if (tmpTable3.Rows.Count > 0)
        //    {
        //        btn_dft_rightDetails.Text = tmpTable3.Rows[0]["note"].ToString();
        //        btn_dft_rightinfo.Text = tmpTable3.Rows[0]["usr_trn"].ToString() + ": " + tmpTable3.Rows[0]["dat_trn"].ToString() + "/" + tmpTable3.Rows[0]["tim_trn"].ToString();
        //    }
        //    else
        //    {
        //        btn_dft_rightDetails.Text = "无信息";
        //    }
        //    //信息公告栏
        //    var tmpTable4 = new DataTable();
        //    strSQL = "select * from (select * from FRSHIFT_L where   type='I' order by dat_trn desc ,tim_trn desc) where rownum<=1";
        //    strResult = DBLink.executeQuery(strSQL, tmpTable4);
        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("查询公告信息时发生异常!");
        //    }

        //    if (tmpTable4.Rows.Count > 0)
        //    {
        //        txtinf.Text = tmpTable4.Rows[0]["NOTE"].ToString();
        //    }
        //    else
        //    {
        //        btn_dft_rightDetails.Text = "无信息";
        //    }
        //    //----------------------
        //    tmpTable.Rows.Clear();
        //    tmpTable1.Rows.Clear();
        //    tmpTable2.Rows.Clear();
        //    tmpTable3.Rows.Clear();
        //    tmpTable4.Rows.Clear();
        //    tmpTable.Dispose();
        //    tmpTable1.Dispose();
        //    tmpTable2.Dispose();
        //    tmpTable3.Dispose();
        //    tmpTable4.Dispose();
        //}

        //private void btnleft_Click(object sender, EventArgs e)
        //{
        //    txtbxleft.Enabled = true;
        //    txtbxleft.ReadOnly = false;

        //    btnsvleft.Visible = true;
        //    btnsvleft.Enabled = true;
        //}

        //private void btnright_Click(object sender, EventArgs e)
        //{
        //    txtbxright.Enabled = true;
        //    btnsvright.Visible = true;
        //    btnsvright.Enabled = true;     // 
        //    txtbxright.ReadOnly = false; //20120905shiping 
        //}

        //private void btnsvleft_Click(object sender, EventArgs e)
        //{
        //    string nDate = DateTime.Now.ToString("yyyy/MM/dd");
        //    string nTime = DateTime.Now.ToString("HH:mm:ss");
        //    String nUser = Global.gUserID;
        //    String nshift = "日班";
        //    String nnote = txtbxleft.Text;
        //    InsertInfoIntotabel(nDate, nTime, nUser, nshift, nnote, "btnleft", "W");
        //    Lblleft.Text = Global.gUserID;
        //    btnsvleft.Visible = false;
        //    //查询信息确认？
        //    //白班+工号+Node
        //}

        //private void btnsvright_Click(object sender, EventArgs e)
        //{
        //    string nDate = DateTime.Now.ToString("yyyy/MM/dd");
        //    string nTime = DateTime.Now.ToString("HH:mm:ss");
        //    String nUser = Global.gUserID;
        //    String nshift = "夜班";
        //    String nnote = txtbxright.Text;
        //    InsertInfoIntotabel(nDate, nTime, nUser, nshift, nnote, "btnright", "W");
        //    Lblright.Text = Global.gUserID;
        //    btnsvright.Visible = false;
        //    //查询信息确认？
        //    //夜班+工号+Node
        //}

        //private Boolean InsertInfoIntotabel(string nDate, string nTime, string nUser, string nshift, string nnote, string strbtn, String strtype)
        //{
        //    //先检查是否有权限做更新
        //    Boolean lRc = checkauth(nUser, strbtn);
        //    if (lRc == false)
        //    {
        //        return false;
        //    }
        //    List<string> listSQL = new List<string>();
        //    String strSQL = "";
        //    String strResult = "";
        //    if (getstrid_prcs().Equals(""))
        //    {
        //        return false;
        //    }
        //    strSQL = "insert into FRSHIFT_L values('" + nDate +
        //                                    "','" + nTime +
        //                                    "','" + nUser +
        //                                    "','" + nnote.Trim() +
        //                                     "','" + nshift +
        //                                    "','" + getstrid_prcs() + "','" + strtype + "')";////////////////////////////
        //    listSQL.Add(strSQL);
        //    strResult = DBLink.executeTrx(listSQL.ToArray());

        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("失败,请重新再试!");
        //        return false;
        //    }
        //    else
        //    {
        //        MessageBox.Show("交接班信息提交成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        //        txtbxleft.Enabled = false;
        //        txtbxright.Enabled = false;
        //        return true;
        //    }

        //}

        //private string getstrid_prcs()
        //{


        //    // else {
        //    strcurprcs = cboPrcsID.Text;
        //    if (strcurprcs.Equals("ADMIN"))
        //    {
        //        if (!cboPrcsID.Text.Trim().Equals(""))
        //        {
        //            return cboPrcsID.Text.Trim();
        //        }
        //        else
        //        {
        //            MessageBox.Show("请选择当前站点!!");//看是否有选择站点
        //            return "";
        //        }

        //    }
        //    else
        //    {
        //        cboPrcsID.Text = strcurprcs;
        //        return strcurprcs;
        //    }

        // }
        // }

        private bool checkauth(string nUser, string strbtn)
        {
            //
            string strSQL = "select a.id_func, a.lin_func, c.btn_func from fdgrpfunc a, fdfunc_m b, fdfunc_d c " +
                       "where a.id_grp in (select id_grp from fdgrpusr where id_usr = '" + nUser + "') " +
                       "and a.id_func = '" + "MAN001" + "' " +
                       "and b.id_func = a.id_func " +
                       "and b.sts_data = 'R' " +
                       "and c.id_func = a.id_func " +
                       "and c.lin_func = a.lin_func " +
                       "and c.sts_data = 'R' " +
                       "and c.btn_func='" + strbtn + "'" +
                       "group by a.id_func, a.lin_func, c.btn_func";

            DataTable dtTable = new DataTable();
            DB.DB DBLink = new DB.DB();
            string strResult = "";
            String strreturn = DBLink.executeQuery(strSQL, dtTable);
            if (!strResult.Equals(""))
            {
                MessageBox.Show("查询产出线别时发生异常!");
                return false;

            }
            else
            {
                if (dtTable.Rows.Count == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

        }

        private void PPT060_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT060(Global.gUserID);

            ShowForm();
        }

        //private void cboPrcsID_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (okflag == true)
        //    {

        //        strcurprcs = cboPrcsID.Text.Trim();
        //        iniinfomationintofrom();
        //    }
        //}

        //private void btn_dft_left_Click(object sender, EventArgs e)
        //{
        //    btn_dft_leftDetails.Enabled = true;
        //    btn_dft_leftsave.Visible = true;
        //    btn_dft_leftDetails.ReadOnly = false;
        //    btn_dft_leftsave.Enabled = true;
        //}

        //private void btn_dft_right_Click(object sender, EventArgs e)
        //{
        //    btn_dft_rightDetails.Enabled = true;
        //    btn_dft_rightsave.Visible = true;
        //    btn_dft_rightDetails.ReadOnly = false;
        //    btn_dft_rightsave.Enabled = true;
        //}

        //private void btn_dft_leftsave_Click(object sender, EventArgs e)
        //{
        //    string nDate = DateTime.Now.ToString("yyyy/MM/dd");
        //    if (dtInput.Enabled == true)
        //    {
        //        nDate = dtInput.Text;
        //    }
        //    string nTime = DateTime.Now.ToString("HH:mm:ss");
        //    String nUser = Global.gUserID;
        //    String nshift = "日班";
        //    String nnote = btn_dft_leftDetails.Text;
        //    InsertInfoIntotabelDefect(nDate, nTime, nUser, nshift, nnote, "btn_dft_leftsave", "M");
        //    btn_dft_leftinfo.Text = Global.gUserID;
        //    btn_dft_leftsave.Visible = false;
        //    dtInput.Enabled = false;
        //    //查询信息确认？
        //    //白班+工号+Node
        //}
        //private void btn_dft_rightsave_Click(object sender, EventArgs e)
        //{
        //    string nDate = DateTime.Now.ToString("yyyy/MM/dd");
        //    if (dtInput.Enabled == true)
        //    {
        //        nDate = dtInput.Text;
        //    }
        //    string nTime = DateTime.Now.ToString("HH:mm:ss");
        //    String nUser = Global.gUserID;
        //    String nshift = "夜班";
        //    String nnote = btn_dft_rightDetails.Text;
        //    InsertInfoIntotabelDefect(nDate, nTime, nUser, nshift, nnote, "btn_dft_rightsave", "M");
        //    btn_dft_rightinfo.Text = Global.gUserID;
        //    btn_dft_rightsave.Visible = false;
        //    dtInput.Enabled = false;
        //    //查询信息确认？
        //    //夜班+工号+Node
        //}
        //private Boolean InsertInfoIntotabelDefect(string nDate, string nTime, string nUser, string nshift, string nnote, string strbtn, string type)
        //{
        //    //先检查是否有权限做更新
        //    Boolean lRc = checkauth(nUser, strbtn);
        //    if (lRc == false)
        //    {
        //        return false;
        //    }
        //    List<string> listSQL = new List<string>();
        //    String strSQL = "";
        //    String strResult = "";
        //    if (getstrid_prcs().Equals(""))
        //    {
        //        return false;
        //    }
        //    strSQL = "select * from frshift_l where dat_trn='" + nDate + "' and shift_prod='" + nshift + "' and id_prcs='" + getstrid_prcs() + "' order by tim_trn desc";
        //    DataTable dtTabletmp = new DataTable();

        //    String strreturn = DBLink.executeQuery(strSQL, dtTabletmp);
        //    if (strreturn.Equals("") && dtTabletmp.Rows.Count > 0)
        //    {
        //        //delete
        //        strSQL = "delete from  FRSHIFT_L  where dat_trn='" + nDate + "' and shift_prod='" + nshift + "' and id_prcs='" + getstrid_prcs() + "'";
        //        listSQL.Add(strSQL);

        //    }
        //    //insert
        //    strSQL = "insert into FRSHIFT_L values('" + nDate +
        //                                "','" + nTime +
        //                                "','" + nUser +
        //                                "','" + nnote.Trim() +
        //                                 "','" + nshift +
        //                                "','" + getstrid_prcs() + "','" + type + "')";////////////////////////////



        //    listSQL.Add(strSQL);
        //    strResult = DBLink.executeTrx(listSQL.ToArray());

        //    if (!strResult.Equals(""))
        //    {
        //        MessageBox.Show("失败,请重新再试!");
        //        return false;
        //    }
        //    else
        //    {
        //        MessageBox.Show("交接班信息提交成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        //        btn_dft_leftDetails.Enabled = false;
        //        btn_dft_rightDetails.Enabled = false;
        //        return true;
        //    }
        //}

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        //private void btn_HandDate_Click(object sender, EventArgs e)
        //{
        //    String nUser = Global.gUserID;
        //    Boolean lRc = checkauth(nUser, "btn_HandDate");
        //    if (lRc == false)
        //    {
        //        return;
        //    }
        //    dtInput.Enabled = true;
        //}

        private void foxConnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();


            frmNow = new PPT.frmPPT064(Global.gUserID);

            ShowForm();
        }

        private void PPT052_Click(object sender, EventArgs e)
        {

        }

        private void PPT065_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT065(Global.gUserID);

            ShowForm();

        }
        /***20120905 shiping** */
        /*主界面最大化调整*/
        protected override void OnResize(EventArgs e)
        {
            try
            {
                if (WindowState == FormWindowState.Maximized)
                {

                    for (int i = 0; i <= conqty - 1; i++)
                    {

                        if (Controls[i].Name.Equals("txtbxleft") || Controls[i].Name.Equals("txtbxright") || Controls[i].Name.Equals("btn_dft_leftDetails") || Controls[i].Name.Equals("btn_dft_rightDetails"))
                        {
                            Controls[i].Width = Convert.ToInt32(this.Width / WW[i] * 8 / 9);
                            Controls[i].Height = Convert.ToInt32(this.Height / HH[i] * 8 / 9);

                        }
                        else if (Controls[i].Name.Equals("txtinf"))
                        {
                            Controls[i].Width = Convert.ToInt32(this.Width / WW[i] * 17 / 18);//1376
                            Controls[i].Height = Convert.ToInt32(this.Height / HH[i] * 3 / 4);//754
                            //Controls[i].Width = 1300;//946
                            //Controls[i].Height = 300;//256
                        }
                        else
                        {
                            Controls[i].Width = Convert.ToInt32(this.Width / WW[i]);
                            Controls[i].Height = Convert.ToInt32(this.Height / HH[i]);
                            Controls[i].Location = new Point(Convert.ToInt32(XX[i] * 4 / 3), Convert.ToInt32(YY[i] * 10 / 9));
                            //    labPS.Top  
                        }
                        frmleft = this.Width;
                    }

                }
                else if (WindowState == FormWindowState.Normal)
                {
                    for (int i = 0; i <= conqty - 1; i++)
                    {

                        if (Controls[i].Name.Equals("txtbxleft") || Controls[i].Name.Equals("txtbxright") || Controls[i].Name.Equals("btn_dft_leftDetails") || Controls[i].Name.Equals("btn_dft_rightDetails"))
                        {
                            Controls[i].Width = Convert.ToInt32(this.Width / WW[i] * 7 / 8);//1016
                            Controls[i].Height = Convert.ToInt32(this.Height / HH[i] * 7 / 8);//678

                        }
                        else if (Controls[i].Name.Equals("txtinf"))
                        {
                            Controls[i].Width = Convert.ToInt32(this.Width / WW[i] * 14 / 15);//1016
                            Controls[i].Height = Convert.ToInt32(this.Height / HH[i] * 9 / 13);//678
                            //Controls[i].Width =  946;
                            //Controls[i].Height = 256;
                        }
                        else
                        {
                            Controls[i].Width = Convert.ToInt32(this.Width / WW[i]);
                            Controls[i].Height = Convert.ToInt32(this.Height / HH[i]);
                            Controls[i].Location = new Point(Convert.ToInt32(XX[i]), Convert.ToInt32(YY[i]));
                        }

                        frmleft = this.Width;

                    }

                }
            }
            catch { };

        }

        private void PPT066_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            //frmNow = new PPT.frmPPT066(Global.gUserID);
            frmNow = new WMS.frmWMS001(Global.gUserID);
            ShowForm();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }


        private void WMS002_Click_1(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            //frmNow = new WMS002.Form1(Global.gUserID);
            frmNow = new WMS.frmWMS002(Global.gUserID);

            ShowForm();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //DateTime dt = DateTime.Now;
            //label1.Visible = false;
            //menuStrip1.Enabled = true;
            //timer1.Stop();

        }

        //private void labPS_Click(object sender, EventArgs e)
        //{
        //    labPS.Text = "文本提示，一系列的字符串！";
        //    // Form frmupdateps = new frmupdateps();
        //    // frmupdateps.ShowDialog();
        //}

        private void WMS003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            //frmNow = new PPT.frmPPT067(Global.gUserID);
            frmNow = new WMS.frmWMS003(Global.gUserID);
            ShowForm();
        }

        private void wMS004_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new WMS.WMS004(Global.gUserID);
            ShowForm();

        }
        private void WMS005_Click_1(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new WMS.frmWMS005(Global.gUserID);
            ShowForm();
        }
        private void wMS002_Click_2(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new WMS.frmWMS002(Global.gUserID);
            ShowForm();
        }



        private void mMS003_Click_1(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new MMS.frmMMS002(Global.gUserID);
            ShowForm();
        }

        private void mMS004_Click(object sender, EventArgs e)
        {

        }

        private void MMS004_Click_1(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new MMS.frmMMS004(Global.gUserID);
            ShowForm();
        }

        private void txtinf_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        //private void btnInfUd_Click(object sender, EventArgs e)
        //{

        //    txtinf.ReadOnly = false;
        //    btnInfSv.Visible = true;
        //    btnInfSv.Enabled = true;
        //}

        //private void btnInfSv_Click(object sender, EventArgs e)
        //{
        //    string chType = txtinf.Text;
        //    for (int i = 0; i < chType.Length; i++)
        //    {
        //        if (chType[i].ToString().Equals("$") || chType[i].ToString().Equals("^"))
        //        {
        //            MessageBox.Show("文本中不可出现 $ 和 ^ 字符", "错误！", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //            return;
        //        }
        //    }
        //    if (txtinf.Text.Trim().Equals(""))
        //    {
        //        return;
        //    }
        //    string nDate = DateTime.Now.ToString("yyyy/MM/dd");
        //    string nTime = DateTime.Now.ToString("HH:mm:ss");
        //    String nUser = Global.gUserID;
        //    String nnote = txtinf.Text;
        //    InsertInfoIntotabel(nDate, nTime, nUser, "", nnote, "btnInfUd", "I");
        //    Lblright.Text = Global.gUserID;
        //    txtinf.ReadOnly = true;
        //    btnInfSv.Visible = false;
        //    Information();
        //}

        //private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    DB.DB DBLink = new DB.DB();
        //    DataTable tab = new DataTable();
        //    string str = cmbInf.Text.Trim().ToString();//厂长指示：夜间车间温度$2012/12/25^18:05:42
        //    string data = str.Substring(str.IndexOf("$") + 1, 10).ToString();
        //    string time = str.Substring(str.IndexOf("^") + 1).ToString();
        //    string message = DBLink.executeQuery("select  note    from  FRSHIFT_L  where   dat_trn ='" + data + "'and tim_trn='" + time + "'", tab);
        //    if (!message.Equals("") || tab.Rows.Count > 0)
        //        txtinf.Text = tab.Rows[0][0].ToString();
        //    tab.Dispose();
        //}

        //private void Information()
        //{
        //    cmbInf.Items.Clear();
        //    DataTable tab = new DataTable();
        //    DB.DB DBlink = new DB.DB();
        //    string message = DBlink.executeQuery("select     substr(note,0,20)||'$'||dat_trn||'^'||tim_trn   as message    from  FRSHIFT_L    where   type='I' and   dat_trn>=to_char(sysdate-7,'yyyy/mm/dd')   order  by dat_trn  desc , tim_trn  desc  ", tab);
        //    if (!message.Equals(""))
        //    {
        //        MessageBox.Show("公告信息查询失败！", "提示！");
        //    }
        //    for (int i = 0; i < tab.Rows.Count; i++)
        //    {
        //        cmbInf.Items.Add(tab.Rows[i]["message"].ToString());
        //    }
        //}



        private void RPT023_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            //frmNow = new RPT.frmRPT033();
            //ShowForm();
        }

        private void WMS006_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS006(Global.gUserID);
            ShowForm();
        }

        private void WMS007_Click(object sender, EventArgs e)
        {
            //   if (frmNow != null)
            //   {
            //       progressCtrl();
            //   }
            ////   frmNow = new WMS.frmWMS007(Global.gUserID);
            //   ShowForm();
        }

        private void RPT024_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            //frmNow = new RPT.frmRPT024();
            //ShowForm();
        }

        private void wMSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //  0071 
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS007(Global.gUserID, "入库", "WHIN", "03", "WMS0071  入库作业");
            ShowForm();
        }

        private void wMS0072_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS007(Global.gUserID, "盘点", "CHECK", "03", "WMS0072  盘点作业");
            ShowForm();
        }

        private void wMS0074_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS007(Global.gUserID, "借出", "BORROW", "03", "WMS0073  借出作业");
            ShowForm();
        }

        private void wMSToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //0073
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS007(Global.gUserID, "重工", "REWOK", "03", "WMS0074  重工作业");
            ShowForm();
        }

        private void wMS0075_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS007(Global.gUserID, "出货", "SHTC", "03", "WMS0075  出货作业");
            ShowForm();
        }

        private void WMS008_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS008(Global.gUserID);

            ShowForm();
        }

        private void WMS009_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS009(Global.gUserID);

            ShowForm();
        }

        private void wMSToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS005(Global.gUserID);

            ShowForm();
        }

        private void WMS010_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS010(Global.gUserID, "", "", "", "");

            ShowForm();
        }

        private void MenuExit_Click(object sender, EventArgs e)
        {

            foreach (Control frm in this.Controls)
            {
                if (frm.GetType().FullName == "System.Windows.Forms.Form")
                {
                    ((Form)frm).Dispose();
                }
            }

            GC.Collect();
            this.Close();
        }

        private void SPC001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new SPC.frmSPC001(Global.gUserID);

            ShowForm();
        }

        private void SPC002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new SPC.frmSPC002(Global.gUserID);

            ShowForm();
        }

        private void SPC003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new SPC.frmSPC003(Global.gUserID);

            ShowForm();
        }

        private void SPC004_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new SPC.frmSPC006(Global.gUserID);

            ShowForm();
        }

        private void RPT025_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new RPT.frmRPT025();

            ShowForm();
        }

        private void PPT066_Click_1(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new PPT.frmPPT066(Global.gUserID);

            ShowForm();
        }

        private void WMS011_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new PPT.frmPPT041(Global.gUserID);

            ShowForm();
        }

        private void RPT026_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new RPT.frmRPT026();

            ShowForm();
        }

        private void WMS012_Click(object sender, EventArgs e)
        {
            //if (frmNow != null)
            //{
            //    progressCtrl();
            //}
            //frmNow = new WMS.frmWMS012(Global.gUserID);

            //ShowForm();
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS016();

            ShowForm();
        }

        private void YuhuiLab_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new PPT.frmPPT069();

            ShowForm();
        }

        private void bRM023ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new BRM.frmBRM023(Global.gUserID);

            ShowForm();
        }

        private void RPT027_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new RPT.frmRPT027();

            ShowForm();
        }

        private void SPC005_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new SPC.frmSPC007(Global.gUserID);

            ShowForm();
        }

        private void SlabelPrint_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }

            frmNow = new PPT.frmPPT072();

            ShowForm();
        }

        private void WMS01301_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new WMS.frmWMS015();
            ShowForm();
        }

        private void MMS005_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new MMS.frmMMS007(Global.gUserID);
            ShowForm();
        }

        private void PPT076_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new PPT.frmPPT076(Global.gUserID, false);

            ShowForm();
        }

        private void IVQ001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQ001();

            ShowForm();
        }

        private void IVQ002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQ002();

            ShowForm();
        }

        private void IVQ003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQ003();

            ShowForm();
        }

        private void IVQ004_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQ004();

            ShowForm();
        }

        private void IVQP001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQP001();

            ShowForm();
        }

        private void IVQP002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQP002();

            ShowForm();
        }

        private void IVQP003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQP003();

            ShowForm();
        }

        private void IVQR002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQR002();

            ShowForm();
        }

        private void IVQI001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQI001();

            ShowForm();
        }

        private void IVQI002_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQI002();

            ShowForm();
        }

        private void IVQI003_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQI003();

            ShowForm();
        }

        private void IVQQ001_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVQuery.frmIVQQ001();

            ShowForm();
        }

        private void IVQMail_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();

            frmNow = new IVERS.frmLogin();

            ShowForm();
        }

        private void progressCtrl()
        {
            //不销毁一次缴库程序的资源
            if (frmNow != null && frmNow.Name != "RemoteServer001")
            {
                frmNow.Dispose();
            }

        }

        private void btnRemoteServer_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new RemoteServer.RemoteServer001();
            ShowForm();
        }

        //ADD BY WZF 2015.09.06 仓库来料
        private void MMS009_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                frmNow.Dispose();
            frmNow = new MMS.frmMMS009(Global.gUserID, "", "");
            Global.SetPPTPara();
            ShowForm();
        }

        //ADD BY WZF 2015.09.06 仓库来料查询
        private void MMS010_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                frmNow.Dispose();
            frmNow = new MMS.frmMMS010(Global.gUserID);
            Global.SetPPTPara();
            ShowForm();
        }

        private void PPT079_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                frmNow.Dispose();
            }
            frmNow = new PPT.frmPPT079(Global.gUserID);
            ShowForm();
        }

        private void WMS01302_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                frmNow.Dispose();
            }
            frmNow = new WMS.frmWMS019();
            ShowForm();
        }

        private void PPT080_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT080(Global.gUserID);
            ShowForm();
        }

        private void RPT029_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new RPT.frmRPT029();
            ShowForm();
        }

        private void PPT081_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT081(Global.gUserID);
            ShowForm();
        }

        private void IVQ005_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new IVQuery.frmIVQ005(Global.gUserID, false);
            ShowForm();
        }

        private void SPC008_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new SPC.frmSPC008(Global.gUserID);
            ShowForm();
        }

        private void PPT085_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT085(Global.gUserID, false);
            ShowForm();
        }

        private void PPT087_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT087(Global.gUserID, false);
            ShowForm();
        }

        private void PPT054_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new PPT.frmPPT054(Global.gUserID);
            ShowForm();
        }

        private void SPC009_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new SPC.frmSPC009();
            ShowForm();
        }

        private void IVQ006_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new IVQuery.frmIVQ006();
            ShowForm();
        }

        private void SPC010_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new SPC.frmSPC010();
            ShowForm();
        }

        private void SCH010_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new SCH.frmSCH010(Global.gUserID);
            ShowForm();
        }

        private void MMS013_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new MMS.frmMMS013(Global.gUserID);
            ShowForm();
        }

        private void MMS015_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new MMS.frmMMS015(Global.gUserID);
            ShowForm();
        }

        private void MMS017_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new MMS.frmMMS017(Global.gUserID);
            ShowForm();
        }

        private void wMS020ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
                progressCtrl();
            frmNow = new WMS.frmWMS020(Global.gUserID);
            ShowForm();
        }

        private void runNgrModule()
        {

            dtpTimFrom.Value = DateTime.Parse(PPT.Global.getServiceDate() + " " + DateTime.Parse("08:00:00").ToString("HH:mm:ss"));
            dtpTimTo.Value = DateTime.Parse(PPT.Global.getServiceDate() + " " + DateTime.Parse("20:00:00").ToString("HH:mm:ss"));


            // grdNgr.Rows.Add(5);
            string sql = "select ID_NGR,   PROGRESS,   STATUSCODE,   FAST_TYPE,   NGR_TYPE,   NUM_PS,   LOT,   SHIFT_PROD,   NAM_EQ," +
                   " START_USR,   START_DEPT,   START_DATE,   START_NOTE,   TN_USR,   TN_DEPT,  " +
                   " GET_USR,   GET_DEPT,   GET_DATE,   ANY_NOTE, " +
                   " DO_USR,   DO_DEPT,   DO_DATE,   DO_NOTE,   DO_RESULT,   DO_REMAIN,  " +
                   " OK_USR,   OK_DEPT,   OK_DATE,   OK_NOTE,   REMAIN" +
                   " from fd_tmfcngr where 1=1 and STATUSCODE='未结案'";

            DataTable dt = new DataTable();
            DB.DB dbLink = new DB.DB();
            string steResult = dbLink.executeQuery(sql, dt);
            dt2Dgv(grdNgr, dt);
            return;
        }


        ///加载部门到grdNgr
        private void loadDeptOnNgr()
        {
            //DataTable dtTable = new DataTable();
            //DB.DB DBLink = new DB.DB();
            //string strSQL = "select lin_cod || ':' || dsc_cod1  from fdsyscod_d where id_cod = 'CODDPT' and sts_data = 'R'";

            //string strResult = DBLink.executeQuery(strSQL, dtTable);
            //if (!strResult.Equals("") || dtTable.Rows.Count == 0)
            //{
            //    return;

            //}
            //else
            //{
            //    START_DEPT.Items.Add("");
            //    TN_DEPT.Items.Add("");
            //    GET_DEPT.Items.Add("");
            //    DO_DEPT.Items.Add("");
            //    OK_DEPT.Items.Add("");
            //    for (int i = 0; i < dtTable.Rows.Count; i++)
            //    {
            //        START_DEPT.Items.Add(dtTable.Rows[i][0].ToString());
            //        TN_DEPT.Items.Add(dtTable.Rows[i][0].ToString());
            //        GET_DEPT.Items.Add(dtTable.Rows[i][0].ToString());
            //        DO_DEPT.Items.Add(dtTable.Rows[i][0].ToString());
            //        OK_DEPT.Items.Add(dtTable.Rows[i][0].ToString());
            //    }
            //}
            return;
        }



        //工号转姓名
        private string cmp2Name(string cmp)
        {
            string sql = " select nam_usr from fduser where id_usr='" + cmp + "'";
            DB.DB dblink = new DB.DB();
            DataTable dt = new DataTable();
            string strResult = dblink.executeQuery(sql, dt);
            if (dt.Rows.Count <= 0)
            {
                return "";
            }
            else
            {
                return dt.Rows[0][0].ToString();
            }
        }



        /// <summary>
        /// DataTable写入DataGridView
        /// </summary>
        /// <param name="grdNgr"></param>
        /// <param name="dt"></param>
        private void dt2Dgv(DataGridView grdNgr, DataTable dt)
        {
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                grdNgr.Rows.Add();
                grdNgr.Rows[p_row].Cells["ID_NGR"].Value = dt.Rows[j]["ID_NGR"].ToString();
                grdNgr.Rows[p_row].Cells["PROGRESS"].Value = dt.Rows[j]["PROGRESS"].ToString();
                grdNgr.Rows[p_row].Cells["STATUSCODE"].Value = dt.Rows[j]["STATUSCODE"].ToString();
                grdNgr.Rows[p_row].Cells["FAST_TYPE"].Value = dt.Rows[j]["FAST_TYPE"].ToString();
                grdNgr.Rows[p_row].Cells["NGR_TYPE"].Value = dt.Rows[j]["NGR_TYPE"].ToString();
                grdNgr.Rows[p_row].Cells["NUM_PS"].Value = dt.Rows[j]["NUM_PS"].ToString();
                grdNgr.Rows[p_row].Cells["LOT"].Value = dt.Rows[j]["LOT"].ToString();
                grdNgr.Rows[p_row].Cells["SHIFT_PROD"].Value = dt.Rows[j]["SHIFT_PROD"].ToString();
                grdNgr.Rows[p_row].Cells["NAM_EQ"].Value = dt.Rows[j]["NAM_EQ"].ToString();
                grdNgr.Rows[p_row].Cells["START_USR"].Value = cmp2Name(dt.Rows[j]["START_USR"].ToString());
                grdNgr.Rows[p_row].Cells["START_DEPT"].Value = dt.Rows[j]["START_DEPT"].ToString();
                grdNgr.Rows[p_row].Cells["START_DATE"].Value = dt.Rows[j]["START_DATE"].ToString().Substring(11, 5);
                if (dt.Rows[j]["START_NOTE"].ToString().IndexOf(":") >= 1)
                {
                    grdNgr.Rows[p_row].Cells["START_NOTE"].Value
                        = dt.Rows[j]["START_NOTE"].ToString().Substring(dt.Rows[j]["START_NOTE"].ToString().IndexOf(":") + 1);
                }
                grdNgr.Rows[p_row].Cells["TN_USR"].Value = dt.Rows[j]["TN_USR"].ToString();
                grdNgr.Rows[p_row].Cells["TN_DEPT"].Value = dt.Rows[j]["TN_DEPT"].ToString();

                grdNgr.Rows[p_row].Cells["GET_USR"].Value = cmp2Name(dt.Rows[j]["GET_USR"].ToString());
                grdNgr.Rows[p_row].Cells["GET_DEPT"].Value = dt.Rows[j]["GET_DEPT"].ToString();
                grdNgr.Rows[p_row].Cells["GET_DATE"].Value = dt.Rows[j]["GET_DATE"].ToString();
                if (dt.Rows[j]["ANY_NOTE"].ToString().IndexOf(":") >= 1)
                {
                    grdNgr.Rows[p_row].Cells["ANY_NOTE"].Value
                        = dt.Rows[j]["ANY_NOTE"].ToString().Substring(dt.Rows[j]["ANY_NOTE"].ToString().IndexOf(":") + 1);
                }

                grdNgr.Rows[p_row].Cells["DO_USR"].Value = cmp2Name(dt.Rows[j]["DO_USR"].ToString());
                grdNgr.Rows[p_row].Cells["DO_DEPT"].Value = dt.Rows[j]["DO_DEPT"].ToString();
                grdNgr.Rows[p_row].Cells["DO_DATE"].Value = dt.Rows[j]["DO_DATE"].ToString();
                if (dt.Rows[j]["DO_NOTE"].ToString().IndexOf(":") >= 1)
                {
                    grdNgr.Rows[p_row].Cells["DO_NOTE"].Value
                        = dt.Rows[j]["DO_NOTE"].ToString().Substring(dt.Rows[j]["DO_NOTE"].ToString().IndexOf(":") + 1);
                }
                grdNgr.Rows[p_row].Cells["DO_RESULT"].Value = dt.Rows[j]["DO_RESULT"].ToString();
                grdNgr.Rows[p_row].Cells["DO_REMAIN"].Value = dt.Rows[j]["DO_REMAIN"].ToString();

                grdNgr.Rows[p_row].Cells["OK_USR"].Value = cmp2Name(dt.Rows[j]["OK_USR"].ToString());
                grdNgr.Rows[p_row].Cells["OK_DEPT"].Value = dt.Rows[j]["OK_DEPT"].ToString();
                grdNgr.Rows[p_row].Cells["OK_DATE"].Value = dt.Rows[j]["OK_DATE"].ToString();
                if (dt.Rows[j]["OK_NOTE"].ToString().IndexOf(":") >= 1)
                {
                    grdNgr.Rows[p_row].Cells["OK_NOTE"].Value
                        = dt.Rows[j]["OK_NOTE"].ToString().Substring(dt.Rows[j]["OK_NOTE"].ToString().IndexOf(":") + 1);
                }
                grdNgr.Rows[p_row].Cells["REMAIN"].Value = int2Form(int.Parse(dt.Rows[j]["REMAIN"].ToString()));
                p_row++;
            }
        }

        /// <summary>
        /// int类型的分钟数转化成汉字,如1天2时32分
        /// </summary>
        /// <param name="va"></param>
        /// <returns></returns>
        public static string int2Form(int va)
        {
            int day = 0, hour = 0, minute = 0;
            day = va / (24 * 60);
            hour = (va - day * 24 * 60) / 60;
            minute = (va - day * 24 * 60 - hour * 60);

            if (day > 0)
            {
                return day + "天" + hour + "时" + minute + "分";
            }
            else if (hour > 0)
            {
                return hour + "时" + minute + "分";
            }
            else
            {
                return minute + "分";
            }
        }

        private void btnNewNgr_Click(object sender, EventArgs e)
        {
            if (frmNow != null)
            {
                progressCtrl();
            }
            frmNow = new TMFC.frmTMFC001(Global.gUserID);
            ShowForm();
        }

        private void btnViewNgr_Click(object sender, EventArgs e)
        {
            string id_ngr = grdNgr.CurrentRow.Cells["ID_NGR"].Value.ToString();
            if (id_ngr.Equals(""))
            {
                MessageBox.Show("所选列无数据!请重选");
                return;
            }

            //检查ID是否存在
            string sql = "select * from fd_tmfcngr where id_ngr ='" + id_ngr + "'";
            DataTable dt = new DataTable();
            DB.DB dblink = new DB.DB();
            string strResult = dblink.executeQuery(sql, dt);
            if (dt.Rows.Count != 1)
            {
                MessageBox.Show("此编号不存在,请重新输入!");
                return;
            }

            if (frmNow != null)
                progressCtrl();
            frmNow = new frmTMFC001(Global.gUserID, id_ngr);
            ShowForm();
        }

        private void btnSelectNgr_Click(object sender, EventArgs e)
        {
            //先清除已有的行
            if (p_row > 0)
            {
                grdNgr.Rows.Clear();
                for (int i = 0; i < 5; i++)
                {
                    grdNgr.Rows.Add();
                }
            }

            p_row = 0;
            string strWhere = " 1=1 ";
            if (chkbDate.Checked)
            {
                strWhere += " and START_DATE >= '" + dtpTimFrom.Text + "'";
                strWhere += " and START_DATE <= '" + dtpTimTo.Text + "'";
            }

            for (int i = 0; i < grdNgr.Rows.Count && chkbDate.Checked == false; i++)
            {

                string strWhereTemp = "";

                #region 组成where条件

                if (grdNgr.Rows[i].Cells["ID_NGR"].Value != null)
                {
                    strWhereTemp += " and ID_NGR='" + grdNgr.Rows[i].Cells["ID_NGR"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["PROGRESS"].Value != null)
                {
                    strWhereTemp += " and PROGRESS='" + grdNgr.Rows[i].Cells["PROGRESS"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["STATUSCODE"].Value != null)
                {
                    strWhereTemp += " and STATUSCODE='" + grdNgr.Rows[i].Cells["STATUSCODE"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["FAST_TYPE"].Value != null)
                {
                    strWhereTemp += " and FAST_TYPE='" + grdNgr.Rows[i].Cells["FAST_TYPE"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["NGR_TYPE"].Value != null)
                {
                    strWhereTemp += " and NGR_TYPE='" + grdNgr.Rows[i].Cells["NGR_TYPE"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["NUM_PS"].Value != null)
                {
                    strWhereTemp += " and NUM_PS like '%" + grdNgr.Rows[i].Cells["NUM_PS"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["LOT"].Value != null)
                {
                    strWhereTemp += " and LOT='" + grdNgr.Rows[i].Cells["LOT"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["SHIFT_PROD"].Value != null)
                {
                    strWhereTemp += " and SHIFT_PROD ='" + grdNgr.Rows[i].Cells["SHIFT_PROD"].Value.ToString() + "'";
                }
                if (grdNgr.Rows[i].Cells["NAM_EQ"].Value != null)
                {
                    strWhereTemp += " and NAM_EQ like '%" + grdNgr.Rows[i].Cells["NAM_EQ"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["START_USR"].Value != null)
                {
                    strWhereTemp += " and START_USR like '%" + grdNgr.Rows[i].Cells["START_USR"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["START_DEPT"].Value != null)
                {
                    strWhereTemp += " and START_DEPT like '%" + grdNgr.Rows[i].Cells["START_DEPT"].Value.ToString() + "%'";

                }
                if (grdNgr.Rows[i].Cells["START_DATE"].Value != null)
                {
                    strWhereTemp += " and START_DATE like '%" + grdNgr.Rows[i].Cells["START_DATE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["START_NOTE"].Value != null)
                {
                    strWhereTemp += " and START_NOTE like '%" + grdNgr.Rows[i].Cells["START_NOTE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["TN_USR"].Value != null)
                {
                    strWhereTemp += " and TN_USR like '%" + grdNgr.Rows[i].Cells["TN_USR"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["TN_DEPT"].Value != null)
                {
                    strWhereTemp += " and TN_DEPT like '%" + grdNgr.Rows[i].Cells["TN_DEPT"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["GET_USR"].Value != null)
                {
                    strWhereTemp += " and GET_USR like '%" + grdNgr.Rows[i].Cells["GET_USR"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["GET_DEPT"].Value != null)
                {
                    strWhereTemp += " and GET_DEPT like'%" + grdNgr.Rows[i].Cells["GET_DEPT"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["GET_DATE"].Value != null)
                {
                    strWhereTemp += " and GET_DATE like'%" + grdNgr.Rows[i].Cells["GET_DATE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["ANY_NOTE"].Value != null)
                {
                    strWhereTemp += " and ANY_NOTE like '%" + grdNgr.Rows[i].Cells["ANY_NOTE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["DO_USR"].Value != null)
                {
                    strWhereTemp += " and DO_USR like '%" + grdNgr.Rows[i].Cells["DO_USR"].Value.ToString() + "%'";

                }
                if (grdNgr.Rows[i].Cells["DO_DEPT"].Value != null)
                {
                    strWhereTemp += " and DO_DEPT like '%" + grdNgr.Rows[i].Cells["DO_DEPT"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["DO_DATE"].Value != null)
                {
                    strWhereTemp += " and DO_DATE like '%" + grdNgr.Rows[i].Cells["DO_DATE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["DO_NOTE"].Value != null)
                {
                    strWhereTemp += " and DO_NOTE like'%" + grdNgr.Rows[i].Cells["DO_NOTE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["DO_RESULT"].Value != null)
                {
                    strWhereTemp += " and DO_RESULT like '%" + grdNgr.Rows[i].Cells["DO_RESULT"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["OK_USR"].Value != null)
                {
                    strWhereTemp += " and OK_USR like '%" + grdNgr.Rows[i].Cells["OK_USR"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["OK_DEPT"].Value != null)
                {
                    strWhereTemp += " and OK_DEPT like '%" + grdNgr.Rows[i].Cells["OK_DEPT"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["OK_DATE"].Value != null)
                {
                    strWhereTemp += " and OK_DATE like '%" + grdNgr.Rows[i].Cells["OK_DATE"].Value.ToString() + "%'";
                }
                if (grdNgr.Rows[i].Cells["OK_NOTE"].Value != null)
                {
                    strWhereTemp += " and OK_NOTE like '%" + grdNgr.Rows[i].Cells["OK_NOTE"].Value.ToString() + "%'";
                }
                #endregion

                ////未输入任何信息则不处理
                if (strWhereTemp.Equals(""))
                {
                    continue;
                }

                strWhere = strWhere + " or ( 1=1 " + strWhereTemp + ")";

            }

            //代表没有任何条件,查询为空
            if (p_row == 0 && strWhere.Equals(" 1=1 "))
            {
                return;
            }

            string sql = "select ID_NGR,   PROGRESS,   STATUSCODE,   FAST_TYPE,   NGR_TYPE,   NUM_PS,   LOT,   SHIFT_PROD,   NAM_EQ," +
                " START_USR,   START_DEPT,   START_DATE,   START_NOTE,   TN_USR,   TN_DEPT,  " +
                " GET_USR,   GET_DEPT,   GET_DATE,   ANY_NOTE, " +
                " DO_USR,   DO_DEPT,   DO_DATE,   DO_NOTE,   DO_RESULT,   DO_REMAIN,  " +
                " OK_USR,   OK_DEPT,   OK_DATE,   OK_NOTE,   REMAIN" +
                " from fd_tmfcngr where " +
                strWhere;

            DataTable dt = new DataTable();
            DB.DB dbLink = new DB.DB();
            string steResult = dbLink.executeQuery(sql, dt);

            dt2Dgv(grdNgr, dt);

            //grdNgr.DefaultCellStyle.BackColor = Color.Transparent;
        }

        private void btnSelectAllNgr_Click(object sender, EventArgs e)
        {
            //先清除已有的行
            grdNgr.Rows.Clear();
            for (int i = 0; i < 5; i++)
            {
                grdNgr.Rows.Add();
            }
            p_row = 0;
            string sql = "select ID_NGR, PROGRESS, STATUSCODE, FAST_TYPE, NGR_TYPE, NUM_PS, LOT, SHIFT_PROD, NAM_EQ," +
                    " START_USR,   START_DEPT,   START_DATE,   START_NOTE,   TN_USR,   TN_DEPT,  " +
                    " GET_USR,   GET_DEPT,   GET_DATE,   ANY_NOTE, " +
                    " DO_USR,   DO_DEPT,   DO_DATE,   DO_NOTE,   DO_RESULT,   DO_REMAIN,  " +
                    " OK_USR,   OK_DEPT,   OK_DATE,   OK_NOTE,   REMAIN" +
                    " from fd_tmfcngr";

            DataTable dt = new DataTable();
            DB.DB dbLink = new DB.DB();
            string steResult = dbLink.executeQuery(sql, dt);

            dt2Dgv(grdNgr, dt);

            // grdNgr.DefaultCellStyle.BackColor = Color.Transparent;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (grdNgr.Rows.Count <= 0 || p_row <= 0)
                return;
            Utile.clsUtile.DataGrid2Excel4(false, grdNgr);
        }





    }
}
